package com.hontech.bv.net.device

import com.hontech.bv.utils.log

class PollTask(private val client: Client) : Runnable {

    companion object {
        const val POLL_TIMEOUT = 5 * 1000L

        fun start(client: Client) {
            TcpConnTask.postDelayed( PollTask(client), POLL_TIMEOUT )
        }
    }

    override fun run() {

        try {
            log("req poll")
            val frame = Frame(Proto.POLL, null)
            client.request(frame, POLL_TIMEOUT)
            log("resp poll")

            TcpConnTask.postDelayed(this, POLL_TIMEOUT)
        } catch (e: Exception) {
            e.printStackTrace()
            client.close()
        }

    }

}


